//
//  TZViewController.swift
//  ad_csj
//
//  Created by admin on 2022/3/9.
//

import Foundation
import UIKit
import TZImagePickerController
import AVFAudio
import AVKit



public extension UIViewController{
	
	@objc func ug_selectImages(config: ((TZImagePickerController)  ->  ())? = nil,
						 finish:@escaping ([UIImage]?,[Any]?,Bool)->()
	){
		let tzImagePicker = TZImagePickerController()
		tzImagePicker.allowTakeVideo = false
		tzImagePicker.allowPickingVideo = false
		tzImagePicker.didFinishPickingPhotosHandle = finish
	
		if let configBlock = config{
			configBlock(tzImagePicker)
		}

	
		tzImagePicker.modalPresentationStyle = .fullScreen
		self.present(tzImagePicker, animated: true, completion: nil)
		
	}
    @objc func ug_selectPushImages(config: ((TZImagePickerController)  ->  ())? = nil,
                         finish:@escaping ([UIImage]?,[Any]?,Bool)->()
    ){
        let tzImagePicker = TZImagePickerController()
        tzImagePicker.allowTakeVideo = false
        tzImagePicker.allowPickingVideo = false
        tzImagePicker.didFinishPickingPhotosHandle = finish
    
        if let configBlock = config{
            configBlock(tzImagePicker)
        }

    
        tzImagePicker.modalPresentationStyle = .fullScreen
        self.navigationController?.pushViewController(tzImagePicker, animated: true)
        
    }
	

	
}

extension FileManager {

	// 判断是否是文件夹的方法
	static func isExists (path: String) -> Bool {

		var directoryExists = ObjCBool.init(false)
		let fileExists = FileManager.default.fileExists(atPath: path, isDirectory: &directoryExists)
		return fileExists && directoryExists.boolValue

	}
	
	func createPathIfNotExit(_ path:String)->Bool{
		var isdir: ObjCBool = ObjCBool(false)
		let isDirExist = fileExists(atPath: path, isDirectory: &isdir)
		if (isdir.boolValue && isDirExist) == false{
			
			do{
				try createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
				return true
			}catch{
				return false
			}
		}else{
			return true
		}
	}

}


